pacman::p_load(tidyverse, sf, lubridate, leaflet, tmap,
raster, spatstat, plotly, DT, classInt, viridis,
ggplot2, sfdep)Take-home Exercise 1b
Getting Started
Loading R package
# Load conflict data
conflict_data <- read_csv("data/MMR.csv")
mmr_shp <- st_read(dsn = "data/geospatial",
layer = "gadm41_MMR_1")Reading layer `gadm41_MMR_1' from data source
`C:\imranmi\ISSS608-VAA\Take-home-ex\Take-home-Ex1b\data\geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 15 features and 11 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 92.1725 ymin: 8.824445 xmax: 101.1768 ymax: 28.54326
Geodetic CRS: WGS 84
# Convert conflict data to an sf object
conflict_sf <- st_as_sf(conflict_data, coords = c("longitude", "latitude"), crs = 4326)Use the SF file, with geometry column
# Filter for battles only
conflict_sf_battles_year <- conflict_sf %>%
filter(event_type == "Battles", year == 2010)
# Plot using leaflet
leaflet(conflict_sf_battles_year) %>%
addTiles() %>%
addCircleMarkers(popup = ~paste("Event: Battles, 2010<br>State/Region:", admin1,
"<br>Actor1:", actor1, "<br>Actor2:", actor2))using the original acled file with long and lat columns
# Filter for battles only
conflict_battles_year <- conflict_data %>%
filter(event_type == "Battles", year == 2010)
# Generate the map
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>% # Base map layer
addCircleMarkers(data = conflict_battles_year,
popup = ~paste("Event: Battles, 2010<br>Admin1:", admin1,
"<br>Actor1:", actor1, "<br>Actor2:", actor2),
radius = 8, # Adjust the size of the markers as needed
fillColor = "red", fillOpacity = 0.8, color = "#FFFFFF", weight = 1) adding an additional layer of base map, mmr_shp to highlight visually MMR alone
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircleMarkers(data = conflict_sf_battles_year,
popup = ~paste("Event: Battles, 2010<br>Region/State:", admin1,
"<br>Actor1:", actor1, "<br>Actor2:", actor2),
radius = 8,
fillColor = "red", fillOpacity = 0.8, color = "#FFFFFF", weight = 1) %>%
addPolygons(data = mmr_shp, color = "#444444", weight = 1, fillOpacity = 0.5) %>% # Adding borders
setView(lng = 96.1603, lat = 19.745, zoom = 6) # Center and zoom the map on Myanmar